package net.mymilkedeek.ludum.tinythumb.states;

import net.mymilkedeek.ludum.tinythumb.Game;
import org.newdawn.slick.*;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

/**
 * TODO: Write Documentation
 *
 * @author Michael Demey
 */
public class EndState extends BasicGameState {
    @Override
    public int getID() {
        return Game.S_END;
    }

    private int choice;
    private String indicator;
    private Image bg;

    @Override
    public void init(GameContainer gameContainer, StateBasedGame stateBasedGame) throws SlickException {
        choice = 1;
        indicator = ">";
        bg = new Image("/resources/spritesheets/end.png");
    }

    @Override
    public void render(GameContainer gameContainer, StateBasedGame stateBasedGame, Graphics graphics) throws SlickException {
        bg.draw(0, 0);

        if (drawScreen) {

            graphics.setColor(Color.white);

            graphics.drawString("What will you do?", 100, 20);
            graphics.drawString("1. Go to your hand.", 100, 100);
            graphics.drawString("2. Stay with Chic.", 100, 130);
        } else {
            graphics.drawString("What will you do?", 100, 20);
        }
    }

    private long time;
    private boolean timed = false;
    private boolean drawScreen;

    @Override
    public void update(GameContainer gameContainer, StateBasedGame stateBasedGame, int i) throws SlickException {
        Input input = gameContainer.getInput();

        if (!timed) {
            timed = true;
            time = System.currentTimeMillis();
            drawScreen = false;
        }

        if (System.currentTimeMillis() - time > 5000) {
            drawScreen = true;
        }

        if (input.isKeyPressed(Input.KEY_1)) {
            choice = Game.S_BAD;
            stateBasedGame.enterState(choice);
        } else if (input.isKeyPressed(Input.KEY_2)) {
            choice = Game.S_GOOD;
            stateBasedGame.enterState(choice);
        }
    }
}